<template>
  <el-row>
    <el-col :span="24">
      <el-card>
        <el-form ref="searchForm" class="el-form-col search-form" :model="search">
          <el-row :gutter="15">
            <el-col :lg="4" :md="6">
              <el-form-item prop="founderName" >
                <el-input v-model="search.founderName" placeholder="创建人" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="startTime">
                <el-date-picker type="date"
                                placeholder="创建开始时间"
                                v-model="search.startTime"
                                value-format="yyyy-MM-dd"
                                style="width: 100%;"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="endTime">
                <el-date-picker type="date"
                                placeholder="创建结束时间"
                                v-model="search.endTime"
                                value-format="yyyy-MM-dd"
                                style="width: 100%;"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item>
                <el-row class="search-btns" :gutter="5">
                  <el-col :span="12">
                    <el-button type="primary" :loading="searchLoading" plain native-type="submit" @click.prevent="searchFunc(search)"><span>搜索</span></el-button>
                  </el-col>
                  <el-col :span="12">
                    <el-button @click="resetFields('searchForm')" plain>重置</el-button>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
          </el-row>

        </el-form>
      </el-card>
    </el-col>
    <el-col :span="24">
      <BasicTable
        ref="BasicTable"
        url="/ms-warehouse-order/moveLocation/findMoveInfoList"
        :tabs="tabs"
        :columns="columns">
        <template slot="buttons">
          <el-button type="primary" @click="addTransfer">新增移库</el-button>
        </template>
        <template slot="column">
          <el-table-column fixed="right" width="100px" align="center" label="操作">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="showDetail(scope.row)"
              >
                详情
              </el-button>
            </template>
          </el-table-column>
        </template>
      </BasicTable>
    </el-col>
  </el-row>
</template>
<script>
import {unixTimestampFilter} from '@/filters'
import {copy} from '@/utils'
export default {
  name: 'transferIndex',
  data() {
    let columns = [
      {
        label: '移库编号',
        data: 'code'
      },
      {
        label: '移库包件数量',
        data: 'moveNum'
      },
      {label: '备注', data: 'memo'},
      {
        label: '创建人',
        data: 'founderName'
      },
      {
        label: '创建时间',
        data: 'foundtime',
        render: (data, type, full, meta) => {
          return unixTimestampFilter(data)
        }
      }
    ]
    return {
      isOpen: false,
      visible: false,
      searchLoading: false,
      search: {
        founderName: '',
        startTime: '',
        endTime: ''
      },
      columns,
      tabs: []
    }
  },
  created() {
  },
  methods: {
    // 搜索
    searchFunc(search) {
      const basicTable = this.$refs.BasicTable
      if (basicTable) {
        let params = copy(search)
        this.searchLoading = true
        basicTable.search(params).finally(_ => {
          this.searchLoading = false
        })
      }
    },
    // 重置表单
    resetFields() {
      const searchForm = this.$refs.searchForm
      if (searchForm) {
        searchForm.resetFields()
      }
    },

    // 表格刷新
    refresh() {
      this.searchFunc(this.search)
    },
    // 跳转详情
    showDetail(data) {
      this.$router.push({path: '/ss-oms/warehouse/transfer/show/' + data.id})
    },
    addTransfer(data) {
      this.$router.push({path: '/ss-oms/warehouse/transfer/Add'})
    }
  }
}
</script>
